package com.usian.article.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.article.mapper.ApArticleConfigMapper;
import com.usian.article.mapper.ApArticleContentMapper;
import com.usian.article.mapper.ApArticleMapper;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.dtos.ArticleHomeDto;
import com.usian.model.article.dtos.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ApArticleServiceImpl extends ServiceImpl<ApArticleMapper, ApArticle> implements ApArticleService {

    @Autowired
    private ApArticleMapper apArticleMapper;

    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;

    @Autowired
    private ApArticleContentMapper apArticleContentMapper;

    @Value("${fileServerUrl}")
    private String host;


    @Override
    public ResponseResult load(Short loadtype, ArticleHomeDto dto) {
        /*检验size */
        Integer size = dto.getSize();
        if (size==null || size==0){
            size = 10;
        }
        dto.setSize(size);

        /*看看是不是更新还是更多*/
        if (loadtype != 1 && loadtype!=2){
            loadtype=2;
        }

        /*判断除了更新 跟多 还有一个刚进页面的默认时间*/
        if (dto.getMaxBehotTime()==null){
            dto.setMaxBehotTime(new Date());
        }

        /*频道 表示也是刚进页面*/
        if (dto.getTag()==null){
            dto.setTag("_all_");
        }

        /*查询ap端文章的数据 */
        List<ApArticle> apArticles = apArticleMapper.findList(dto, loadtype);

        ResponseResult responseResult = ResponseResult.okResult(apArticles);
        responseResult.setHost(host);

        return responseResult;
    }


}
